<script type="text/javascript">
 /* <![CDATA[ */ 
   function  addZoomToMap() {
     gmap.addControl(new GLargeMapControl (),
               new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(3, 3)));
   }
<% if @region %>

    function viewCurrentF() {
     gmap.clearOverlays();
    var rectBounds = new GLatLngBounds(
        new GLatLng(<%= @region.end_y %>, <%= @region.start_x %>),
        new GLatLng(<%= @region.start_y %>, <%= @region.end_x %>));
    gmap.setZoom(gmap.getBoundsZoomLevel(rectBounds));
    gmap.addOverlay(new Rectangle(rectBounds));
    gmap.panTo(new GLatLng(<%= @map_center_y %>, <%= @map_center_x %>));
    }     
    
  <% if @ecase_region %> 
    function  addMapViews() {
      gmap.addControl(new ViewRectanglesControl());
    }
   function viewAllF() {
     gmap.clearOverlays();
     var rectBounds = new GLatLngBounds(
        new GLatLng(<%= @ecase_region.end_y %>, <%= @ecase_region.start_x %>),
        new GLatLng(<%= @ecase_region.start_y %>, <%= @ecase_region.end_x %>));
     var rectArray =  [<%= @regions_collection.join(",") %>]
     gmap.setZoom(gmap.getBoundsZoomLevel(rectBounds));
     gmap.addOverlay(new Rectangle(rectBounds));
     for( var i=0 ; i < rectArray.length ; i ++ ){
        var rectSmallBounds = new GLatLngBounds(
        new GLatLng(rectArray[i][3], rectArray[i][0]),
        new GLatLng(rectArray[i][2], rectArray[i][1]));
        gmap.addOverlay(new Rectangle(rectSmallBounds));
     }
     gmap.panTo(new GLatLng(<%= @map_center_y %>, <%= @map_center_x %>));
    }  
  <% end %>
<% elsif !@e_regions.nil?  && (@e_regions.size > 0) %>
    function viewAllEcases() {
     gmap.clearOverlays();
     var rectArray =  [<%= @e_regions.join(",") %>];
     var rectSmallBounds , r;
     for( var i=0 ; i < rectArray.length ; i ++ ){
        rectSmallBounds = new GLatLngBounds(
        new GLatLng(Number(rectArray[i][3]), Number(rectArray[i][0])),
        new GLatLng(Number(rectArray[i][2]), Number(rectArray[i][1])) );
        r = new Rectangle(rectSmallBounds);
        gmap.addOverlay(r);
     }
    } 
<% elsif @ecase_region %>
    function moveToEcaseRegion() {
     var rectBounds = new GLatLngBounds(
        new GLatLng(<%= @ecase_region.end_y %>, <%= @ecase_region.start_x %>),
        new GLatLng(<%= @ecase_region.start_y %>, <%= @ecase_region.end_x %>));
       gmap.setZoom(gmap.getBoundsZoomLevel(rectBounds));  
    }
<% end %>
/* ]]> */
</script>